﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace cancerportal.Models
{
    public class symptomModels : Data.DataBaseConnection
    {
        public static Entitys.symptomEntity sym;
        public static List<Entitys.symptomEntity> getSymptom()
        {
            List<Entitys.symptomEntity> listReturn = new List<Entitys.symptomEntity>();

            string query = string.Format("select * from cancerportal.dbo.symptom");
            try
            {
                open();
                DBCommand.CommandText = query;
                reader = DBCommand.ExecuteReader();
                while (reader.Read())
                {
                    sym = new Entitys.symptomEntity();
                    sym.symptom_id = (int)(reader["symptom_id"]);
                    sym.symptom_name = (string)(reader["symptom_name"]);
                    sym.symptom_name = (string)(reader["symptom_detail"]);

                    listReturn.Add(sym);
                }
            }
            finally
            {
                close();
            }
            return listReturn;
        }
        public static Entitys.symptomEntity getSymptomByID(int symID)
        {
            sym = new Entitys.symptomEntity();
            string query = "select * from cancerportal.dbo.symptom where symptom_id = @id";
            try
            {
                open();
                DBCommand.CommandText = query;
                DBCommand.Parameters.AddWithValue("@id", symID);
                reader = DBCommand.ExecuteReader();
                while (reader.Read())
                {
                    sym.symptom_id = (int)(reader["symptom_id"]);
                    sym.symptom_name = (string)(reader["symptom_name"]);
                    sym.symptom_name = (string)(reader["symptom_detail"]);
                }
            }
            finally
            {
                close();
            }
            return sym;
        }

        public static Entitys.symptomEntity getSymptomByName(string name)
        {
            sym = new Entitys.symptomEntity();
            string query = "select * from cancerportal.dbo.symptom where symptom_name = @name";
            try
            {
                open();
                DBCommand.CommandText = query;
                DBCommand.Parameters.AddWithValue("@name", name);
                reader = DBCommand.ExecuteReader();
                while (reader.Read())
                {
                    sym.symptom_id = (int)(reader["symptom_id"]);
                    sym.symptom_name = (string)(reader["symptom_name"]);
                    sym.symptom_name = (string)(reader["symptom_detail"]);
                }
            }
            finally
            {
                close();
            }
            return sym;
        }

        public static bool checkExistSymptom(string symp)
        {
            bool test = false;
            string query = "select * from cancerportal.dbo.symptom where symptom_name = @word";
            try
            {
                open();
                DBCommand.CommandText = query;
                DBCommand.Parameters.AddWithValue("@word", symp);
                reader = DBCommand.ExecuteReader();
                if (reader.Read())
                {
                    test = true;
                }
            }
            finally
            {
                close();
            }
            return test;
        }
        
    }
}